package com.maila.xiaoaoschool.api;

import android.content.Context;

import com.maila.xiaoaoschool.net.NetWork;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.maila.xiaoaoschool.util.Constants;

import java.util.HashMap;

/**
 * Created by mark on 2017/12/8.
 */

public class PrefApi extends NetWork {
    public static final String URL_XIAOAO_PREF = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=mapipreferential"; //版本服务器地址

    public PrefApi(Context ctx, VolleyInterface listener) {
        super(ctx, listener);
    }


    /**
     * 特惠美食 商品列表
     *
     * @param adcode
     * @param page
     * @param size
     */
    public void getXiaoSalegoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "preferential_food", query);
    }

    public void getSalelistBytype(int type, String adcode, int page, int size) {
        switch (type) {
            case 1:
                getNewUserSaleGoods(adcode, page, size);
                break;
            case 2:
                getCountalegoods(adcode, page, size);
                break;
            case 3:
                getTodaySaleGoods(adcode, page, size);
                break;
            case 4:
                getManjianSaleGoods(adcode, page, size);
                break;
            case 5:
                getBounesSaleGoods(adcode, page, size);
                break;
            default:
                break;

        }
    }

    /**
     * 限时抢购 商品列表
     *
     * @param adcode
     * @param page
     * @param size
     */
    public void getCountalegoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "time_food", query);
    }

    /**
     * 获取新用户立减列表
     */
    public void getNewUserSaleGoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "new_food", query);
    }

    /**
     * 获取今日特价列表
     */
    public void getTodaySaleGoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "today_food", query);
    }

    /**
     * 获取满减商品列表
     */
    public void getManjianSaleGoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "manjian_food", query);
    }

    /**
     * 获取返券商品列表
     */
    public void getBounesSaleGoods(String adcode, int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("adcode", adcode);
        query.put("page", page);
        query.put("size", size);
        requestPost(URL_XIAOAO_PREF, "fanquan_food", query);
    }

    /**
     * 支付
     *
     * @param order_id
     * @param allcost
     * @param paytype
     * @param dno
     * @param pay_password
     */
    public void pay_order(String order_id, String allcost, int paytype, String dno, String pay_password) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("order_id", order_id);
        query.put("allcost", allcost);
        query.put("paytype", paytype);
        query.put("dno", dno);
        query.put("pay_password", pay_password);
        requestPost(URL_XIAOAO_PREF, "pay", query);
    }

    /**
     * 结算时的优惠券列表
     * @param cost
     * @param shopid
     */
    public void pay_coupon_list(String cost, String shopid) {
        HashMap<String, Object> query = new HashMap<>();
        query.put("cost", cost);
        query.put("shopid", shopid);
        requestGet(URL_XIAOAO_PREF, "quan_list", query);
    }



    public void getwxinfo(String code) {
        requestGet("https://api.weixin.qq.com/sns/oauth2/access_token?appid="+Constants.APP_ID_WX+"&secret="+Constants.APP_SECRET+"&code="+code+"&grant_type=authorization_code", null, null);
    }


}
